// -----------------------------------------------------------------------
// <copyright file="ProfileTypeEN.cs" company="VDC-IT" author="LTDUC">
//      Copyright (c) VDC-IT. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace VDC.VONE.ENTITIES
{
    using System;
    using System.Collections.Generic;
    using System.Data.SqlClient;
    using Microsoft.ApplicationBlocks.Data;
    using VDC.COMMON;
    
    /// <summary>
    /// Class ProfileType
    /// </summary>
    public class ProfileTypeEN : EntityEN
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ProfileTypeEN" /> class
        /// </summary>
        public ProfileTypeEN()
        {
            this.ProfileTypeId = 0;
            this.WorkflowId = 0;
            this.DepartmentId = 0;
            this.ProfileTypeGroupId = 0;
            this.ImplementationListId = 0;
            this.ResultsImplementationListId = 0;
            this.Code = string.Empty;
            this.Name = string.Empty;
            this.AmountProfile = 0;
            this.ResolveDays = 0;
            this.Fees = 0;
        }

        /// <summary>
        /// Gets or sets ProfileTypeId
        /// </summary>
        public int ProfileTypeId { get; set; }

        /// <summary>
        /// Gets or sets WorkflowId
        /// </summary>
        public int WorkflowId { get; set; }

        /// <summary>
        /// Gets or sets DepartmentId
        /// </summary>
        public int DepartmentId { get; set; }

        /// <summary>
        /// Gets or sets ProfileTypeGroupId
        /// </summary>
        public int ProfileTypeGroupId { get; set; }

        /// <summary>
        /// Gets or sets ImplementationListId
        /// </summary>
        public int ImplementationListId { get; set; }

        /// <summary>
        /// Gets or sets ResultsImplementationListId
        /// </summary>
        public int ResultsImplementationListId { get; set; }

        /// <summary>
        /// Gets or sets Code
        /// </summary>
        public string Code { get; set; }

        /// <summary>
        /// Gets or sets Name
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets AmountProfile
        /// </summary>
        public int AmountProfile { get; set; }

        /// <summary>
        /// Gets or sets ResolveDays
        /// </summary>
        public int ResolveDays { get; set; }

        /// <summary>
        /// Gets or sets Fees
        /// </summary>
        public decimal Fees { get; set; }

        /// <summary>
        /// Gets Workflow
        /// </summary>
        public WorkflowEN Workflow
        {
            get
            {
                try
                {
                    WorkflowEN workflow = null;
                    SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneWorkflowGetById, this.WorkflowId);

                    while (reader.Read())
                    {
                        workflow = new WorkflowEN();

                        if (!reader.IsDBNull(0))
                        {
                            workflow.WorkflowId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            workflow.Code = reader.GetString(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            workflow.Name = reader.GetString(2);
                        }

                        if (!reader.IsDBNull(3))
                        {
                            workflow.CreateDate = reader.GetDateTime(3);
                        }

                        if (!reader.IsDBNull(4))
                        {
                            workflow.Descriptions = reader.GetString(4);
                        }

                        if (!reader.IsDBNull(5))
                        {
                            workflow.Active = reader.GetBoolean(5);
                        }
                    }

                    reader.Close();
                    reader.Dispose();

                    return workflow;
                }
                catch (SqlException ex)
                {
                    LogHelper.Instance.WriteError(ex);
                    throw new Exception(ex.ToString());
                }
            }
        }

        /// <summary>
        /// Gets Department
        /// </summary>
        public DepartmentEN Department
        {
            get
            {
                try
                {
                    DepartmentEN department = null;
                    SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneDepartmentGetById, this.DepartmentId);

                    while (reader.Read())
                    {
                        department = new DepartmentEN();

                        if (!reader.IsDBNull(0))
                        {
                            department.DepartmentId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            department.Code = reader.GetString(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            department.Name = reader.GetString(2);
                        }

                        if (!reader.IsDBNull(3))
                        {
                            department.Parent = reader.GetInt32(3);
                        }

                        if (!reader.IsDBNull(4))
                        {
                            department.Order = reader.GetInt32(4);
                        }
                    }

                    reader.Close();
                    reader.Dispose();

                    return department;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }

        /// <summary>
        /// Gets ProfileTypeGroup
        /// </summary>
        public ProfileTypeGroupEN ProfileTypeGroup
        {
            get
            {
                try
                {
                    ProfileTypeGroupEN profileTypeGroup = null;
                    SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneProfileTypeGroupGetById, this.ProfileTypeGroupId);

                    while (reader.Read())
                    {
                        profileTypeGroup = new ProfileTypeGroupEN();

                        if (!reader.IsDBNull(0))
                        {
                            profileTypeGroup.ProfileTypeGroupId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            profileTypeGroup.Name = reader.GetString(1);
                        }
                    }

                    reader.Close();
                    reader.Dispose();

                    return profileTypeGroup;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }

        /// <summary>
        /// Gets ImplementationList
        /// </summary>
        public ImplementationListEN ImplementationList 
        {
            get
            {
                try
                {
                    ImplementationListEN implementationList = null;
                    SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneImplementationListGetById, this.ImplementationListId);

                    while (reader.Read())
                    {
                        implementationList = new ImplementationListEN();

                        if (!reader.IsDBNull(0))
                        {
                            implementationList.ImplementationListId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            implementationList.Name = reader.GetString(1);
                        }
                    }

                    reader.Close();
                    reader.Dispose();

                    return implementationList;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }

        /// <summary>
        /// Gets ResultsImplementationList
        /// </summary>
        public ResultsImplementationListEN ResultsImplementationList
        {
            get
            {
                try
                {
                    ResultsImplementationListEN resultsImplementationList = null;
                    SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneResultsImplementationListGetById, this.ResultsImplementationListId);

                    while (reader.Read())
                    {
                        resultsImplementationList = new ResultsImplementationListEN();

                        if (!reader.IsDBNull(0))
                        {
                            resultsImplementationList.ResultsImplementationListId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            resultsImplementationList.Name = reader.GetString(1);
                        }
                    }

                    reader.Close();
                    reader.Dispose();

                    return resultsImplementationList;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }

        /// <summary>
        /// Gets Profiles
        /// </summary>
        public IList<ProfileEN> Profiles
        {
            get
            {
                try
                {
                    IList<ProfileEN> lstProfile = new List<ProfileEN>();
                    SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneProfileGetAll);
                    while (reader.Read())
                    {
                        ProfileEN profile = new ProfileEN();

                        if (!reader.IsDBNull(0))
                        {
                            profile.ProfileId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            profile.ProfileStatusId = reader.GetInt32(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            profile.ProfileTypeId = reader.GetInt32(2);
                        }

                        if (!reader.IsDBNull(3))
                        {
                            profile.LevelId = reader.GetInt16(3);
                        }

                        if (!reader.IsDBNull(4))
                        {
                            profile.StorageLocationProfileListId = reader.GetInt32(4);
                        }

                        if (!reader.IsDBNull(5))
                        {
                            profile.CreateUserId = reader.GetInt32(5);
                        }

                        if (!reader.IsDBNull(6))
                        {
                            profile.Code = reader.GetString(6);
                        }

                        if (!reader.IsDBNull(7))
                        {
                            profile.Name = reader.GetString(7);
                        }

                        if (!reader.IsDBNull(8))
                        {
                            profile.SmsGet = reader.GetString(8);
                        }

                        if (!reader.IsDBNull(9))
                        {
                            profile.Email = reader.GetString(9);
                        }

                        if (!reader.IsDBNull(10))
                        {
                            profile.CreateDate = reader.GetDateTime(10);
                        }

                        if (!reader.IsDBNull(11))
                        {
                            profile.ReceivingDate = reader.GetDateTime(11);
                        }

                        if (!reader.IsDBNull(12))
                        {
                            profile.AppointmentDate = reader.GetDateTime(12);
                        }

                        if (!reader.IsDBNull(13))
                        {
                            profile.Object = reader.GetBoolean(13);
                        }

                        if (!reader.IsDBNull(14))
                        {
                            profile.SettlementDate = reader.GetDateTime(14);
                        }

                        if (!reader.IsDBNull(15))
                        {
                            profile.Notes = reader.GetString(15);
                        }

                        if (!reader.IsDBNull(16))
                        {
                            profile.Attachments = reader.GetString(16);
                        }

                        if (!reader.IsDBNull(17))
                        {
                            profile.ContentWork = reader.GetString(17);
                        }

                        if (!reader.IsDBNull(18))
                        {
                            profile.IsDelete = reader.GetBoolean(18);
                        }

                        if (!reader.IsDBNull(19))
                        {
                            profile.OrganName = reader.GetString(19);
                        }

                        if (!reader.IsDBNull(20))
                        {
                            profile.Address = reader.GetString(20);
                        }

                        if (!reader.IsDBNull(21))
                        {
                            profile.Phone = reader.GetString(21);
                        }

                        lstProfile.Add(profile);
                    }

                    reader.Close();
                    reader.Dispose();
                    return lstProfile;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }

        /// <summary>
        /// Gets ProfileTypeCompositionProfileLists
        /// </summary>
        public IList<ProfileTypeCompositionProfileListEN> ProfileTypeCompositionProfileLists
        {
            get
            {
                try
                {
                    IList<ProfileTypeCompositionProfileListEN> lstProfileTypeCompositionProfileList = new List<ProfileTypeCompositionProfileListEN>();
                    var reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneProfileTypeCompositionProfileListGetByProfileTypeId, this.ProfileTypeId);
                    while (reader.Read())
                    {
                        ProfileTypeCompositionProfileListEN profileTypeCompositionProfileList = new ProfileTypeCompositionProfileListEN();
                        if (!reader.IsDBNull(0))
                        {
                            profileTypeCompositionProfileList.ProfileTypeCompositionProfileListId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            profileTypeCompositionProfileList.ProfileTypeId = reader.GetInt32(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            profileTypeCompositionProfileList.CompositionProfileListId = reader.GetInt32(2);
                        }

                        lstProfileTypeCompositionProfileList.Add(profileTypeCompositionProfileList);
                    }

                    reader.Close();
                    reader.Dispose();
                    return lstProfileTypeCompositionProfileList;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }

        /// <summary>
        /// Gets ProfileTypeLegalGroundsLists
        /// </summary>
        public IList<ProfileTypeLegalGroundsListEN> ProfileTypeLegalGroundsLists
        {
            get
            {
                try
                {
                    IList<ProfileTypeLegalGroundsListEN> lstProfileTypeLegalGroundsList = new List<ProfileTypeLegalGroundsListEN>();
                    var reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneProfileTypeLegalGroundsListGetByProfileTypeId, this.ProfileTypeId);
                    while (reader.Read())
                    {
                        ProfileTypeLegalGroundsListEN profileTypeLegalGroundsList = new ProfileTypeLegalGroundsListEN();
                        if (!reader.IsDBNull(0))
                        {
                            profileTypeLegalGroundsList.ProfileTypeLegalGroundsListId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            profileTypeLegalGroundsList.ProfileTypeId = reader.GetInt32(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            profileTypeLegalGroundsList.LegalGroundsListId = reader.GetInt32(2);
                        }

                        lstProfileTypeLegalGroundsList.Add(profileTypeLegalGroundsList);
                    }

                    reader.Close();
                    reader.Dispose();
                    return lstProfileTypeLegalGroundsList;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }

        /// <summary>
        /// Gets ProfileTypeRequirementsLists
        /// </summary>
        public IList<ProfileTypeRequirementsListEN> ProfileTypeRequirementsLists
        {
            get
            {
                try
                {
                    IList<ProfileTypeRequirementsListEN> lstProfileTypeLegalGroundsList = new List<ProfileTypeRequirementsListEN>();
                    var reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, Constants.StorepProcedure.VOneProfileTypeRequirementsListGetByProfileTypeId, this.ProfileTypeId);
                    while (reader.Read())
                    {
                        ProfileTypeRequirementsListEN profileTypeRequirementsList = new ProfileTypeRequirementsListEN();
                        if (!reader.IsDBNull(0))
                        {
                            profileTypeRequirementsList.ProfileTypeRequirementsListId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            profileTypeRequirementsList.RequirementsListId = reader.GetInt32(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            profileTypeRequirementsList.ProfileTypeId = reader.GetInt32(2);
                        }

                        lstProfileTypeLegalGroundsList.Add(profileTypeRequirementsList);
                    }

                    reader.Close();
                    reader.Dispose();
                    return lstProfileTypeLegalGroundsList;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }
    }
}
